package com.yuanfeng.biz.front.buy.dao;

import com.yuanfeng.entity.Books;
import com.yuanfeng.util.JdbcUtil;
import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanHandler;

public class BookSearchDaoImpl implements BookSearchDao {

	private Books book;
	@Override
	public Books searchBook(String bookName) {

		try {
			//获取数据库连接
			QueryRunner qr = new QueryRunner(JdbcUtil.getDataSource());
			book = (Books) qr.query("select * from books where NAME=?", new BeanHandler(Books.class),
					new Object[] {bookName});
		} catch (Exception e) {
			e.printStackTrace();
			throw new RuntimeException();
		}
		System.out.println(book);
		if(book != null)
			//返回查询到的图书对象
			return book;
		else
			return null;
	}

}
